package com.jin.crud.common.exception;

import com.jin.crud.common.code.HttpCodeEnum;
import lombok.Getter;

/**
 * @Author yuxuejin
 * @Date 2021/11/12 17:35
 * @Description: 自定义异常
 */
@Getter
public class ResultException extends RuntimeException {

    private static final long serialVersionUID = 7133651385712198609L;
    private final int code;

    /**
     * 使用已有的错误类型
     * @param type 枚举类中的错误类型
     */
    public ResultException(HttpCodeEnum type){
        super(type.getMsg());
        this.code = type.getCode();
    }

    /**
     * 自定义错误类型
     * @param code 自定义的错误码
     * @param msg 自定义的错误提示
     */
    public ResultException(int code, String msg){
        super(msg);
        this.code = code;
    }

}
